﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Research.Kinect.Nui;
using System.Reactive.Subjects;

namespace Kinect.KinectMouseControl
{
    public class LeftHandRaisedGesture : IEventPublisher<bool>
    {
        private IEventPublisher<SkeletonData> _skeletonDataPublisher;
        private Subject<bool> _leftHandRaisedSubject;

        public LeftHandRaisedGesture(IEventPublisher<SkeletonData> skeletonDataPublisher)
        {
            _leftHandRaisedSubject = new Subject<bool>();

            _skeletonDataPublisher = skeletonDataPublisher;
            _skeletonDataPublisher.EventObservable.Subscribe(x => ProcessSkeletonData(x));
        }

        private void ProcessSkeletonData(SkeletonData skeletonData)
        {
            var handLeft = skeletonData.Joints[JointID.HandLeft];
            var elbowLeft = skeletonData.Joints[JointID.ElbowLeft];

            _leftHandRaisedSubject.OnNext(handLeft.Position.Y > elbowLeft.Position.Y);
        }

        #region IEventPublisher<bool> Members

        public IObservable<bool> EventObservable
        {
            get { return _leftHandRaisedSubject; }
        }

        #endregion
    }
}
